import * as api from "../../plugins/api.js"
import * as types from './mutation-types'

export const session = async function ({
  commit
}) {
  try {
    let data = await api.session()
    if (data.usertype != "Admin") {
      data = false
      return data
    } else {
      commit(types.SET_U, data)
      return true
    }
  } catch (err) {
    return false
  }
}

export const login = async function ({
  commit
}, datas) {
  try {
    let data = await api.asynclogin(datas)
    commit(types.SET_U, data)
    return data
  } catch (err) {
    throw (err)
  }
}



export const actionUser = async function ({
  commit
}, datas) {
  try {
    let data = await api.allUser(datas)
    commit(types.SET_USER, data)
  } catch (err) {
    throw (err)
  }
}

//


export const actionCatebag = async function ({
  commit
}, datas) {
  try {
    let data = await api.getAllCatebag(datas)
    commit(types.SET_CATEBAG, data)
  } catch (err) {
    throw (err)
  }
}

export const actionCatebagtype = async function ({
  commit
}, datas) {
  try {
    let data = await api.getAllCatebagtype(datas)
    commit(types.SET_CATEBAGTYPE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionCourse = async function ({
  commit
}, datas) {
  try {
    let data = await api.getallcourse(datas)
    commit(types.SET_COURSE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionFileurl = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetFileurlall();
    commit(types.SET_FILEURL, data)
  } catch (err) {
    throw (err)
  }
}

export const actionIframe = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetiframelist()
    commit(types.SET_IFRAME, data)
  } catch (err) {
    throw (err)
  }
}

export const actionPackege = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetAllPackege(datas)
    commit(types.SET_PACKEGE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionVideo = async function ({
  commit
}, option) {
  try {
    let data = await api.asyncGetVideoList(option)
    commit(types.SET_VIDEO, data.VideoList)
  } catch (err) {
    throw (err)
  }
}


export const actionwechattemp = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetwechattemp();
    commit(types.SET_WECHATTEMP, data);
  } catch (err) {
    throw (err)
  }
}

export const actionCoursecatebag = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetcoursecatebag();
    commit(types.SET_COURSECATEBAG, data);
  } catch (err) {
    throw (err)
  }
}

export const actionSecretfile = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetsecretfile({ order: "paixu", limit: 2000 });
    commit(types.SET_SECRETFILE, data);
  } catch (err) {
    throw (err)
  }
}

export const actionTeacherproposal = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetteacherproposal({ order: "paixu", limit: 2000 });
    commit(types.SET_TEACHERPROPOSAL, data);
  } catch (err) {
    throw (err)
  }
}

export const actionTpdata = async function ({
  commit
}) {
  try {
    let data = await api.asyncgettpdata({ order: "paixu", limit: 2000 });
    commit(types.SET_TPDATA, data);
  } catch (err) {
    throw (err)
  }
}

export const actionVideoCategories = async function ({
  commit
}) {
  try {
    let data = await api.asyncGetCategories();
    if (data.SubCategories && data.SubCategories.Category) {
      data = data.SubCategories.Category
    } else {
      data = []
    }
    commit(types.SET_VIDEOCATEGORIES, data);
  } catch (err) {
    throw (err)
  }
}